﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;

public enum E_Slider_Type
{
    Horizontal,
    Vertical,
}

public class CustomGUISlider : CustomGUIControl
{
    public float minValue = 0;
    public float maxValue = 0;
    public float nowValue = 0;
    public E_Slider_Type type = E_Slider_Type.Horizontal;
    public GUIStyle styleThumb;
    public UnityAction <float>changeValue;
    private float oldVal = 0;
    protected override void StyleOffDraw()
    {
        if (type == E_Slider_Type.Horizontal)
            nowValue = GUI.HorizontalSlider(guiPos.Pos, nowValue, minValue, maxValue);
        else
            nowValue = GUI.VerticalSlider(guiPos.Pos, nowValue, minValue, maxValue);

        if (nowValue != oldVal)
        {
            changeValue?.Invoke(nowValue);
            oldVal = nowValue;
        }
    }

    protected override void StyleOnDraw()
    {
        if (type == E_Slider_Type.Horizontal)
            nowValue = GUI.HorizontalSlider(guiPos.Pos, nowValue, minValue, maxValue, style, styleThumb);
        else
            nowValue = GUI.VerticalSlider(guiPos.Pos, nowValue, minValue, maxValue, style, styleThumb);

        if (nowValue != oldVal)
        {
            changeValue?.Invoke(nowValue);
            oldVal = nowValue;
        }
    }
}
